Terraform では明示的に渡さないと GCE インスタンスのデフォルトサービスアカウント設定されない
from Container-Optimized OS
#Terraform
systemctl start node-problem-detector してもメトリック送られない
ログ見る
Feb 21 14:28:37 valheim01 node-problem-detector739: 2021/02/21 14:28:37 Failed to export to Stackdriver: rpc error: code = Unauthenticated desc = transport: metadata: GCE metadata "instance/service-accounts/default/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fmonitoring%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fmonitoring.read%2Chttps%3A%2F%2Fwww.googleapis.com%2Fauth%2Fmonitoring.write" not defined
認証コケてる
scopes
https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/monitoring
https://www.googleapis.com/auth/monitoring.read
https://www.googleapis.com/auth/monitoring.write
$ curl -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
{"error":"invalid_request","error_description":"Service account not enabled on this instance"}
インスタンスのデフォルトサービスアカウントが無い?
インスタンスのサービス アカウントの作成と有効化  |  Compute Engine ドキュメント  |  Google Cloud
google_compute_instance | Resources | hashicorp/google | Terraform Registry
ないことあるのか?
インスタンスのサービス アカウントの作成と有効化  |  Compute Engine ドキュメント  |  Google Cloud
By default, all Compute Engine instances can run as the default service account. When you create an instance using the gcloud command-line tool or the Cloud Console, and omit any service account specifications, the default service account is assigned to the instance.
terraform でセットアップするとき、明示的に渡さないと無効なのかな
コンソールから作ってみるとどうなるか見る
https://gyazo.com/4dcb2c59b4ceb33134fb48d5a6ce5a20
curl で metadata server から取れた
* Terraform からは明示的にサービスアカウント設定する必要ある
google_compute_instance | Resources | hashicorp/google | Terraform Registry
google_compute_default_service_account | Data Sources | hashicorp/google | Terraform Registry
code:compute_engine.tf
data "google_compute_default_service_account" "default" {
}
resource "google_compute_instance" "gameserver" {
...
service_account {
email = data.google_compute_default_service_account.default.email
scopes = "cloud-platform"
}
}
で使える
インスタンスのサービスアカウントの設定にはインスタンスを停止しないといけない
apply 時に止まってもいいなら allow_stopping_for_update = true をつけておく